// @FileName  :memory.c
// @Time      :2024/5/11 11:21
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>

typedef struct node {
    int st, sz;
    struct node *nxt;
} *node;
node head = NULL, p, t, q, o;
int n, i, j, st, sz, a;

int main() {
    scanf("%d", &n);
    while (n--) {
        scanf("%d %d", &st, &sz);
        if (head == NULL) {
            p = (struct node *) malloc(sizeof(struct node));
            head = p;
        } else {
            p->nxt = (struct node *) malloc(sizeof(struct node));
            p = p->nxt;
        }
        p->st = st, p->sz = sz, p->nxt = NULL;
    }
    p->nxt = head;
    o = p;
    p = head;
    //模拟请求
    while (~scanf("%d", &a)) {
        if (a == -1) break;
        else {
            if (o->nxt->sz == a) {
                q = p;
                p = p->nxt;
                o->nxt = p;
                free(q); //删除头节点
            } else if (p->sz > a)
                p->sz -= a;//减去
            else {
                t = p; //用t来记录p
                while (p->nxt != t) {
                    if (p->nxt->sz > a) {
                        p->nxt->sz -= a; //减去
                        p = p->nxt;
                        break;
                    } else if (p->nxt->sz == a) {
                        q = p->nxt;
                        p->nxt = p->nxt->nxt;
                        p = p->nxt;
                        free(q); //删除节点
                        break;
                    }
                    o = p; //跟踪 p
                    p = p->nxt;
                }
                if (p->nxt == t) //如果循环一圈也没有找到符合标准的
                {
                    o = p, p = t; //重置
                }
            }
        }
    }
    printf("%d %d\n", p->st, p->sz); //输出头节点信息
    t = p->nxt;
    while (t != p) {
        printf("%d %d\n", t->st, t->sz); //输出之后一圈的信息
        t = t->nxt;
    }
    return 0;
}
/*
12
1024 512
8192 512
16384 1024
32768 3072
65536 8192
77824 1024
80896 8192
96016 1024
101136 5120
119328 512
134448 1024
142640 3072
1024 2560 10240 512 2048 6400 2560 5600 2000 -1
 */
